package org.pushforward.iwillsurvive.helpers;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class Error404Handler - The Page Not Found
 */
@WebServlet(description = "Constructs the 404 Error", urlPatterns = { "/404" })
public class Error404Handler extends HttpServlet 
{
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Error404Handler() 
    {
        super();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	@Override
	protected void doGet(HttpServletRequest request, 
						 HttpServletResponse response) 
						 throws ServletException, IOException 
	{
		String standard404Title = "iWillSurvive 404 Error Page";
		String standard404Heading = "Error 404 - Page not Found";
		String standard404Message = "What are you looking 404?<br><br>\n" +
				"There seems to be nothing where you're looking.<br><br>\n" +
				"How about you try clicking " + PageBuilder.indexHereLink + ".<br>\n";
		String message = request.getParameter("ErrorMessage");

		PageBuilder.GenerateErrorPage(response, standard404Title, standard404Heading, 
									  standard404Message, message, 404);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException 
	{
		doGet(request, response);
	}

}
